//package com.fenbi.tutor.live.module.large.large.chat.lithoview
//
//import android.app.Activity
//import android.os.Handler
//import android.util.Log
//import android.view.GestureDetector
//import android.view.GestureDetector.SimpleOnGestureListener
//import android.view.LayoutInflater
//import android.view.MotionEvent
//import android.view.View
//import android.view.ViewGroup
//import android.widget.FrameLayout
//import android.widget.TextView
//import androidx.recyclerview.widget.LinearLayoutManager
//import androidx.recyclerview.widget.RecyclerView
//import androidx.recyclerview.widget.RecyclerView.SimpleOnItemTouchListener
//import com.fenbi.tutor.live.common.helper.ViewHelper
//import com.fenbi.tutor.live.engine.common.userdata.base.IUserData
//import com.fenbi.tutor.live.engine.conan.SendMessage
//import com.fenbi.tutor.live.frog.IFrogLogger
//import com.fenbi.tutor.live.module.large.chat.BaseChatMsgAdapter
//import com.fenbi.tutor.live.module.large.chat.ChatMsgDataFetcher.ChatMsgUserDataWrapper
//import com.fenbi.tutor.live.module.large.chat.ChatMsgHelper
//import com.fenbi.tutor.live.module.large.large.chat.BaseChatModuleView
//import com.fenbi.tutor.live.module.large.large.chat.BaseChatPresenter
//import com.fenbi.tutor.live.module.large.large.chat.ChatContract
//import com.fenbi.tutor.live.module.large.large.chat.ChatMsgAdapter
//import com.fenbi.tutor.live.module.large.large.chat.ChatMsgAdapter.MessageDecorator
//import com.fenbi.tutor.live.module.large.large.chat.ChatMsgFilterType
//import com.yuanfudao.android.common.util.ResUtils
//import com.yuantiku.android.common.app.util.UiUtils
//import java.util.ArrayList
//
///**
// * TODO 简要描述
// * @author wkm @ Zebra Inc.
// * @since 09-19-2020
// */
//
//class LithoChatModuleView : ChatContract.IView{
//
//    protected val TAG = BaseChatModuleView::class.java.simpleName
//
//    protected var activity: Activity? = null
//
//
//    protected var swipeRefreshLayout: FrameLayout? = null
//
//    protected var recyclerView: RecyclerView? = null
//
//    private var linearLayoutManager: LinearLayoutManager? = null
//
//    private var chatAdapter: ChatMsgAdapter? = null
//
//    protected var baseChatPresenter: BaseChatPresenter<*>? = null
//
//    protected var newMsgView: TextView? = null
//
//    protected var chatHintView: TextView? = null
//
//    protected var logger: IFrogLogger? = null
//
//    private val hasUpPage = true
//
//    protected var lastAtBottom = true
//
//    protected var waitForLoading = false
//
//    protected var liveBottomBanText: TextView? = null
//
//    protected var liveBottomButtonContainer: View? = null
//
//    protected var liveBottomBanTextContainer: View? = null
//
//    protected val filterList = arrayOf(
//        ChatMsgFilterType.DEFAULT, ChatMsgFilterType.FOR_ME
//    )
//
//    protected var curFilterIndex = 0
//
//    fun BaseChatModuleView(activity: Activity?, viewRoot: ViewGroup?, chatPresenter: BaseChatPresenter<*>?) {
//        this.activity = activity
//        baseChatPresenter = chatPresenter
//        liveChatContainerView = LayoutInflater.from(activity).inflate(R.layout.live_view_live_chat, viewRoot, true)
//        swipeRefreshLayout = liveChatContainerView!!.findViewById(R.id.live_swipe_refresh)
//        recyclerView = liveChatContainerView!!.findViewById(R.id.live_list)
//        newMsgView = liveChatContainerView!!.findViewById(R.id.live_new_msg_toast)
//        chatHintView = liveChatContainerView!!.findViewById(R.id.live_chat_input_hint)
//        newMsgView.setOnClickListener(View.OnClickListener { scrollToBottom() })
//        liveBottomBanText = liveChatContainerView!!.findViewById(R.id.live_bottom_ban_text)
//        liveBottomButtonContainer = liveChatContainerView!!.findViewById(R.id.live_bottom_button_container)
//        liveBottomBanTextContainer = liveChatContainerView!!.findViewById(R.id.live_bottom_ban_text_container)
//        ViewHelper.setChildOnClickListener(liveChatContainerView, viewIds, this)
//        initGestureRecyclerView()
//    }
//
//    private val viewIds = intArrayOf(
//        R.id.live_chat_container, R.id.live_chat_input_hint
//    )
//
//    fun onClick(v: View?) {}
//
//
//    protected fun decorateMessageBlock(message: SendMessage): CharSequence {
//        return if (message.getContent() == null) "" else message.getContent()
//    }
//
//    fun setFrogLogger(logger: IFrogLogger?) {
//        this.logger = logger
//    }
//
//    override fun detach() {
//        if (chatAdapter != null) {
//            chatAdapter!!.release()
//        }
//        if (activity != null) {
//            activity = null
//        }
//    }
//
//    override fun notifyChatMsgChanged(notifyType: Int, data: Any) {
//        when (notifyType) {
//            ChatMsgHelper.NOTIFY_TYPE_ADD_SINGLE -> onNotifySingleMsg(data as IUserData)
//            ChatMsgHelper.NOTIFY_TYPE_ADD_MULTI -> onNotifyMultiMsg(data as Collection<IUserData>)
//            ChatMsgHelper.NOTIFY_TYPE_SHOW_LATEST -> onNotifyShowLatest()
//            ChatMsgHelper.NOTIFY_TYPE_NEW_MSG -> onNotifyNewMsg(data as Int)
//            ChatMsgHelper.NOTIFY_TYPE_DEFAULT -> onNotifyDefault()
//            else -> {
//            }
//        }
//    }
//
//    override fun setChatStyleVersion(version: Long) {}
//
//    private fun onNotifyNewMsg(count: Int) {
//        newMsgView!!.text = ResUtils.getString(R.string.live_chat_new_message)
//    }
//
//    private fun onNotifySingleMsg(data: IUserData?) {
//        if (data == null) {
//            return
//        }
//        if (ChatMsgFilterType.checkMsgFilterType(data, filterList[curFilterIndex])) {
//            //            final int preCount = chatAdapter.getItemCount();
//            chatAdapter!!.addMsgToList(data, lastAtBottom)
//            //            truncateInMemMsgIfNeed();
//            chatAdapter!!.notifyDataSetChanged()
//            autoScrollToBottomIfNeed()
//        }
//    }
//
//    private fun onNotifyMultiMsg(collection: Collection<IUserData>?) {
//        if (collection != null) {
//            val preCount = chatAdapter!!.itemCount
//            val list: MutableList<IUserData> = ArrayList()
//            for (data in collection) {
//                if (ChatMsgFilterType.checkMsgFilterType(data, filterList[curFilterIndex])) {
//                    list.add(data)
//                }
//            }
//            chatAdapter!!.addAllMsgToList(list, lastAtBottom)
//            chatAdapter!!.notifyDataSetChanged()
//            autoScrollToBottomIfNeed()
//        }
//    }
//
//
//    private fun onNotifyShowLatest() {
//        scrollToBottom()
//    }
//
//    private fun onNotifyDefault() {
//        chatAdapter!!.clearData()
//        chatAdapter!!.notifyDataSetChanged()
//        scrollToBottom()
//    }
//
//    private fun truncateInMemMsgIfNeed() {
//        if (chatAdapter!!.listCount > BaseChatMsgAdapter.IN_MEM_MSG_CAPACITY) {
//            chatAdapter!!.truncateMsgs()
//            chatAdapter!!.notifyDataSetChanged()
//        }
//    }
//
//    private fun autoScrollToBottomIfNeed() {
//        if (lastAtBottom || chatAdapter!!.listCount >= BaseChatMsgAdapter.IN_MEM_MSG_CAPACITY + BaseChatMsgAdapter.IN_MEM_MSG_CAPACITY_APPEND) {
//            scrollToBottom()
//        } else {
//            newMsgView!!.visibility = View.VISIBLE
//        }
//    }
//
//    protected fun scrollToBottom() {
//        truncateInMemMsgIfNeed()
//        recyclerView!!.scrollToPosition(linearLayoutManager!!.itemCount - 1)
//        recyclerView!!.scrollBy(0, UiUtils.dip2pix(100f))
//        newMsgView!!.visibility = View.GONE
//        lastAtBottom = true
//        totalScrollY = 0
//        baseChatPresenter!!.notifyScrollEnd()
//    }
//
//    private fun isScrolledToBottom(): Boolean {
//        Log.d(
//            "isScrolledToBottom", linearLayoutManager
//                .findLastCompletelyVisibleItemPosition().toString() + " second:" + linearLayoutManager
//                .getItemCount()
//        )
//        return linearLayoutManager
//            .findLastCompletelyVisibleItemPosition() == linearLayoutManager
//            .getItemCount() - 1
//    }
//
//}